/*
 *	Copyright © 2013 Changsha Shishuo Network Technology Co., Ltd. All rights reserved.
 *	长沙市师说网络科技有限公司 版权所有
 *	http://www.shishuo.com
 */

package com.shishuo.cms.action.manage;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shishuo.cms.constant.ConfigConstant;
import com.shishuo.cms.entity.Config;
import com.shishuo.cms.entity.vo.JsonVo;

/**
 * 网站配置action
 * 
 * @author Herbert
 * 
 */
@Controller
@RequestMapping("/manage/config")
public class ManageConfigAction extends ManageBaseAction {

	/**
	 * 网站配置
	 * 
	 * @author Administrator
	 * 
	 */
	@RequestMapping(value = "/basic.htm", method = RequestMethod.GET)
	public String basic(ModelMap modelMap) {
		List<Config> configList = configService.getConfigByKeyList( Arrays.asList(ConfigConstant.ABOUT));
		modelMap.addAttribute("configList", configList);
		return "/manage/config/basic";
	}

	/**
	 * 修改网站配置
	 * 
	 * @author Administrator
	 * 
	 */
	@ResponseBody
	@RequestMapping(value = "/basic.json", method = RequestMethod.POST)
	public JsonVo<String> basicSubmit(
			@RequestParam(value = "about_tel") String about_tel,
			@RequestParam(value = "about_qq") String about_qq,
			@RequestParam(value = "about_name") String about_name,
			@RequestParam(value = "about_chuanzhen") String about_chuanzhen,
			@RequestParam(value = "about_email") String about_email,
			@RequestParam(value = "about_url") String about_url,
			@RequestParam(value = "about_addr") String about_addr,
			ModelMap modelMap) {
		JsonVo<String> json = new JsonVo<String>();
		try {
			// 检测校验结果
			validate(json);
			Map<String, String> map=new HashMap<String, String>();
			map.put(ConfigConstant.ABOUT_TEL, about_tel);
			map.put(ConfigConstant.ABOUT_QQ, about_qq);
			map.put(ConfigConstant.ABOUT_NAME, about_name);
			map.put(ConfigConstant.ABOUT_CHUANZHEN, about_chuanzhen);
			map.put(ConfigConstant.ABOUT_EMAIL, about_email);
			map.put(ConfigConstant.ABOUT_URL, about_url);
			map.put(ConfigConstant.ABOUT_ADDR, about_addr);
			configService.updagteConfigByKeyList(map);
			json.setResult(true);
		} catch (Exception e) {
			json.setResult(false);
			json.setMsg(e.getMessage());
		}
		return json;

	}

}
